import { snakeCase } from 'change-case'
import { DefaultNamingStrategy } from 'typeorm'

/**
 * typeorm 名称策略
 */
export class NamingStrategy extends DefaultNamingStrategy {
  columnName(
    propertyName: string,
    customName: string,
    embeddedPrefixes: string[]
  ): string {
    if (customName) return customName
    return snakeCase(propertyName)
  }

  tableName(targetName: string, userSpecifiedName: string): string {
    if (userSpecifiedName) return userSpecifiedName
    return snakeCase(targetName.replace('Entity', ''))
  }
}
